//
//  LZMyCollectionViewCell.m
//  laziz_Consumer
//
//  Created by ZhaoDongBo on 2016/10/26.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZMyCollectionViewCell.h"

#import "GVUserDefaults+LZProperties.h"

#import "Masonry.h"

@implementation LZMyCollectionViewCell

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self configView];
        [self addAutoLayout];
    }
    return self;
}

- (void)configView {
    [self.contentView addSubview:self.iconImageView];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.line1];
    [self.contentView addSubview:self.line2];
}

- (void)addAutoLayout {
    
    WS(weakSelf);

    [self.iconImageView makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(39);
        make.size.mas_equalTo(CGSizeMake(33.5, 33.5));
        make.centerX.mas_equalTo(weakSelf.centerX);
    }];
    
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.iconImageView.mas_bottom).with.offset(12);
        make.leading.mas_equalTo(10);
        make.trailing.mas_equalTo(-10);
    }];
  
    [self.line1 makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.trailing.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.width.mas_equalTo(0.75);
    }];
    
    [self.line2 makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(0);
        make.trailing.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.height.mas_equalTo(0.75);
    }];
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    if ([GVUserDefaults standardUserDefaults].authType == kAuthType_completeAuth) {
        self.contentView.backgroundColor    = UIColorFromRGB(0xffffff, 1);
        self.titleLabel.textColor           = UIColorFromRGB(0x485760, 1);
        self.line1.backgroundColor = UIColorFromRGB(0xeeeeee, 1);
        self.line2.backgroundColor = UIColorFromRGB(0xeeeeee, 1);
        if (self.indexPath.row % 2 == 1) {
            self.line1.hidden = YES;
        }
        else {
            self.line1.hidden = NO;
        }
        
        if (self.indexPath.row == 8 || self.indexPath.row == 9) {
            self.line2.hidden = YES;
        }
        else {
            self.line2.hidden = NO;
        }
    }
    else {
        
        self.titleLabel.textColor       = UIColorFromRGB(0x999999, 1);
        self.line1.backgroundColor = UIColorFromRGB(0xffffff, 0.15);
        self.line2.backgroundColor = UIColorFromRGB(0xffffff, 0.15);
        self.contentView.backgroundColor = [UIColor clearColor];
        if (self.indexPath.row % 2 == 1) {
            self.line1.hidden = YES;
        }
        else {
            self.line1.hidden = NO;
        }
        
        if (self.indexPath.row == 8 || self.indexPath.row == 9) {
            self.line2.hidden = YES;
        }
        else {
            self.line2.hidden = NO;
        }
    }
}

#pragma mark - Setter/Getter

- (UIImageView *)iconImageView {

    if (_iconImageView == nil) {
        _iconImageView = [[UIImageView alloc] init];
    }
    
    return _iconImageView;
}

- (UILabel *)titleLabel {

    if (_titleLabel == nil) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font            = [UIFont systemFontOfSize:15];
        _titleLabel.textAlignment   = NSTextAlignmentCenter;
    }
    
    return _titleLabel;
}

- (UIView *)line1 {

    if (_line1 == nil) {
        _line1 = [[UIView alloc] init];
        _line1.backgroundColor = UIColorFromRGB(0xffffff, 0.15);
        _line1.hidden = YES;
    }
    
    return _line1;
}

- (UIView *)line2 {
    
    if (_line2 == nil) {
        _line2 = [[UIView alloc] init];
        _line2.backgroundColor = UIColorFromRGB(0xffffff, 0.15);
        _line2.hidden = YES;
    }
    
    return _line2;
}

@end
